package com.etoak.common.jwt;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys;

import java.security.Key;
import java.util.Date;
import java.util.Map;

public class JwtUtil {

    private static String SECRET_KEY="pangtouyupangtouyupangtouyupangt";

    private static Key KEY = Keys.hmacShaKeyFor(SECRET_KEY.getBytes());

    private static  Long EXPIRE = 1000l*60*60*12;
    public static String create(Map<String, Object> claimsMap) {
        /**
         * 创建jwt
         */
        Date now = new Date();
        return Jwts.builder().signWith(KEY).setIssuedAt(new Date(now.getTime()+EXPIRE)).setClaims(claimsMap).compact();
    }
    public static Map<String,Object> parse(String token) {
        return Jwts.parserBuilder().setSigningKey(KEY).build().parseClaimsJws(token).getBody();
    }

}
